﻿var date = [];
var aqi = [];
var pm25 = [];
var pm10 = [];
var no2 = [];
var so2 = [];
var co = [];
var o3 = [];
var dataList = null;

var myChart1;
option1 = {
    tooltip: {
       trigger: 'axis',
        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    title: {
        left: 'center',
        text: '矛盾纠纷案件统计'
    },
    legend: {
        top: '30',
        data: ['平安无事','矛盾纠纷'],
        selected: {
            // 选中'系列1'
            '平安无事': true,
            '矛盾纠纷': true,
            '轻度污染': false,
            '中度污染': false,
            '重度污染': false, 
            '严重污染': false,
        }
    },
    grid: {
		left:'5%',
		right: '5%'
	},
    xAxis: {
        type: 'category',
        //boundaryGap: false,
        data: date
    },
    yAxis: {
        type: 'value',
        name: '天数',
        nameLocation: 'middle',
        nameGap: 50
		//,
       // boundaryGap: [0, '100%']
    },
//    dataZoom: [{
//        type: 'inside',
//        start: 0,
//        end: 10
//    }, {
//        start: 0,
//        end: 10
//    }],
    series: [
        {
            name: '优',
            type: 'bar',
			//barWidth: 60,
			stack: '空气质量',
             
            data: aqi,
            itemStyle:{
                normal:{
                    color:'#0f0'
                }
            }
        },
        {
            name:'良',
            type:'bar',
			//barWidth: 60,
           
			stack: '空气质量',
            
            data: pm25,
            itemStyle:{
                normal:{
                    color:'#ff0'
                }
            }
        },
        {
            name:'轻度污染',
            type:'bar',
			//barWidth: 60,
            
			stack: '空气质量',
            
            data: pm10,
            itemStyle:{
                normal:{
                    color:'#FF7E00'
                }
            }
        },
        {
            name: '中度污染',
            type: 'bar',
			//barWidth: 60,
            
			stack: '空气质量',
            
            data: so2,
            itemStyle:{
                normal:{
                    color:'#f00'
                }
            }
        },
        {
            name: '重度污染',
            type: 'bar',
			//barWidth: 60,
         
			stack: '空气质量',
            
            data: no2,
            itemStyle:{
                normal:{
                    color:'#99004C'
                }
            }
        },
        {
            name: '严重污染',
            type: 'bar',
			//barWidth: 60,
            
			stack: '空气质量',
            
            data: co,
            itemStyle:{
                normal:{
                    color:'#7E0023'
                }
            }
        }
    ]
};

$(function () {
    var d = new Date();
    var vYear = d.getFullYear();
    var select = document.getElementById("selYear");
    for (vYear; vYear > 2014; vYear--) {
        option = new Option(vYear, vYear);
        select.options.add(option);
    }
    queryData();
});

function queryData(){
   var year = $("#selYear").val();
    var month = $("#selMonth").val();
    var reqUrl = 'test2?type=enviro&op=getCityStatistic&param={year:"' + year + '",month:"' + month + '"}';
    $.ajax({
        url: reqUrl,type: "get",dataType:"json",
        success: function (dataStr) {
			if (dataStr != null) {
                dataList = dataStr;
			    setEcharts(dataStr[0]);
				//myChart1.on('legendselectchanged', eConsole);
			}
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        },
        contentType: "application/json; charset=utf-8"
    });
}

function setEcharts(data){
		var option={
		xAxis:{data:dataList[0].GetTime},
		series:[{data:data.Excellent},{data:data.Good},{data:data.Slight},{data:data.Middle},{data:data.Servere},{data:data.Serious},
		]
		};
		if(!myChart1){
				$("body").css("height",($(window).height()*0.99)+"px");
         myChart1 = echarts.init(document.getElementById('line'));
		  myChart1.setOption(option1);
		}
        
		 myChart1.setOption(option);
		

       
}

function eConsole(param){
	
	option1.series[0].areaStyle = {normal: {}};
	var myChart1 = echarts.init(document.getElementById('line'));
	myChart1.setOption(option1);
	myChart1.on('legendselectchanged', eConsole);
}

function aqiStatistic(){
    setEcharts(dataList[0]);
}

function pmStatistic(){
    setEcharts(dataList[1]);
}


Date.prototype.Format = function (fmt) { //author: meizz   
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日   
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}


